package com.thekernel.youdaoyun.service;

import com.thekernel.youdaoyun.YoudaoyunApplication;
import com.thekernel.youdaoyun.bean.User;
import com.thekernel.youdaoyun.exception.MyException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @Author TheKernel
 * @Date 2019/9/12 7:31 下午
 * @Version 1.0
 * @Description
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = YoudaoyunApplication.class)
public class testUserService {

    @Autowired
    private UserService userService;

    @Test
    public void testRegisterWithoutUsername() throws Exception {
        User user = new User();

        user.setPassword("test");
        user.setUserType(1);

        int result = this.userService.register(user);
        System.out.println(result);
    }

    @Test
    public void testRegisterWithExistedUsername() throws Exception {
        User user = new User();

        user.setUsername("1711090325");
        user.setPassword("test");
        user.setUserType(1);

        int result = this.userService.register(user);
        System.out.println(result);
    }

    @Test
    public void testViewSelf() throws MyException {
        User user = this.userService.viewSelf();
        System.out.println(user);

        Assert.assertEquals("1711090325", user.getUsername());
        Assert.assertNull(user.getPassword());
    }

}
